<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="text"> 
        <button @click="addTodo">add</button>
        <ul>
            <li v-for="todo in todos">
                {{todo.text}}
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el:"#app",
            data:{
                text:"",
                todos:[
                    {id:0,text:"天气之子"},
                    {id:1,text:"你的名字"},
                    {id:2,text:"言叶之庭"},
                ]
            },
            methods:{
                addTodo(){
                    if(this.text != ""){
                        this.todos.push({
                        id:this.length,
                        text:this.text
                        })
                    }
                    
                    this.text=""
                }
            }
        })
    </script>

</body>
</html>